﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import flash.utils.*;

    public class ThemeDefinition implements IThemeDefinition {

        private var m_items:Dictionary;
        private var m_themeItemsXML:XMLList;

        public function ThemeDefinition(_arg1:XML){
            this.m_items = new Dictionary();
            this.m_themeItemsXML = _arg1.items.item;
        }
        public function getThemeItemByName(_arg1:String, _arg2:Item=null):Item{
            var _local3:XML;
            if (_arg2 == null){
                _arg2 = Global.gameSettings.getItemByName(_arg1);
            };
            if (this.m_items[_arg1] == null){
                for each (_local3 in this.m_themeItemsXML) {
                    if (_local3.@name == _arg1){
                        this.m_items[_arg1] = new Item(this.applyThemeXML(_local3, _arg2.xml));
                        break;
                    };
                };
                if (this.m_items[_arg1] == null){
                    this.m_items[_arg1] = _arg2;
                };
            };
            return (this.m_items[_arg1]);
        }
        private function applyThemeXML(_arg1:XML, _arg2:XML):XML{
            var _local5:XML;
            var _local6:XMLList;
            var _local7:XML;
            var _local3:XML = _arg2.copy();
            var _local4:XMLList = _arg1.elements();
            for each (_local5 in _local4) {
                _local6 = _local3.elements(_local5.name());
                for each (_local7 in _local6) {
                    if (this.compareElements(_local5, _local7)){
                        _local7.replace("*", _local5.elements());
                    };
                };
            };
            return (_local3);
        }
        private function compareElements(_arg1:XML, _arg2:XML):Boolean{
            var _local3 = (_arg1.name() == _arg2.name());
            var _local4 = (_arg1.attributes() == _arg2.attributes());
            return (((_local3) && (_local4)));
        }

    }
}//package Classes 
